package com.tengju.bff.interfaces.manage.crm.dealer;

import com.tengju.bff.interfaces.shared.ApiResponse;
import com.tengju.bff.interfaces.shared.export.BaseExportQuery;
import com.tengju.bff.interfaces.shared.servlet.ManageEntrance;
import com.tengju.bff.interfaces.shared.servlet.ServletContextUtil;
import com.tengju.export.application.ExportService;
import com.tengju.export.domain.record.ExportDataType;
import com.tengju.export.domain.record.ExportFileType;
import com.tengju.user.domain.model.user.UserIdCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Validated
@RestController
@Api(tags = "生意参谋-经销商查询-数据导出")
@RequestMapping(value = "manage/crm/dealer/report")
@Slf4j
@ManageEntrance
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class ReportDealerInfoController {

    private final ExportService exportService;

    @ApiOperation(value = "本月新增导出", notes = "本月新增导出")
    @RequestMapping(value = "/current/increase/export", method = RequestMethod.GET)
    @RequiresRoles("sso")
    public ApiResponse<Object> asyncExportCurrentMonthIncrease() {
        long staffId = ServletContextUtil.getServletContext().getStaffId().getValue();
        String realName = ServletContextUtil.getServletContext().getRealName();
        List<UserIdCode> genSecIdCodes = ServletContextUtil.getServletContext().getGenSecIdCodes();
        BaseExportQuery exportQuery = new BaseExportQuery();
        exportQuery.setGenSecIdCodes(genSecIdCodes);
        exportService.exportData("本月新增服务商列表", ExportFileType.XLSX,
                "currentIncreaseExportDataSourceRepository",
                ExportDataType.TABLE, exportQuery,
                staffId, realName);
        return ApiResponse.newSuccess();
    }

    @ApiOperation(value = "签约中服务商导出", notes = "签约中服务商导出")
    @RequestMapping(value = "/signing/step/export", method = RequestMethod.GET)
    @RequiresRoles("sso")
    public ApiResponse<Object> asyncExportSigningStep() {
        long staffId = ServletContextUtil.getServletContext().getStaffId().getValue();
        String realName = ServletContextUtil.getServletContext().getRealName();
        List<UserIdCode> genSecIdCodes = ServletContextUtil.getServletContext().getGenSecIdCodes();
        BaseExportQuery exportQuery = new BaseExportQuery();
        exportQuery.setGenSecIdCodes(genSecIdCodes);
        exportService.exportData("签约中服务商列表", ExportFileType.XLSX,
                "signingStepExportDataSourceRepository",
                ExportDataType.TABLE, exportQuery,
                staffId, realName);
        return ApiResponse.newSuccess();
    }

    @ApiOperation(value = "即将晋升服务商导出", notes = "即将晋升服务商导出")
    @RequestMapping(value = "/target/star/export", method = RequestMethod.GET)
    @RequiresRoles("sso")
    public ApiResponse<Object> asyncExportTargetStar() {
        long staffId = ServletContextUtil.getServletContext().getStaffId().getValue();
        String realName = ServletContextUtil.getServletContext().getRealName();
        List<UserIdCode> genSecIdCodes = ServletContextUtil.getServletContext().getGenSecIdCodes();
        BaseExportQuery exportQuery = new BaseExportQuery();
        exportQuery.setGenSecIdCodes(genSecIdCodes);
        exportService.exportData("即将晋升服务商列表", ExportFileType.XLSX,
                "targetStarExportDataSourceRepository",
                ExportDataType.TABLE, exportQuery,
                staffId, realName);
        return ApiResponse.newSuccess();
    }

}
